package it.getta.vicinometro.utils;

import it.getta.vicinometro.adapter.SwipeIndicatorAdapter;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.SpinnerAdapter;

public class SwipeIndicatorGallery extends SinglePageGallery {

	protected Context mContext;
	protected SwipeIndicatorAdapter mSwipeAdapter;
	private OnAttachedToWindow mOnAttachedToWindow;
	
	public interface OnAttachedToWindow {
		public void onAttached();
	}
	
	public SwipeIndicatorGallery(Context context) {
		super(context);
		mContext = context;
	}
	
	
	public SwipeIndicatorGallery(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		}


	public SwipeIndicatorGallery(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
	}

	@Override
	protected void onAttachedToWindow() {
		super.onAttachedToWindow();
		if(mOnAttachedToWindow != null) {
			mOnAttachedToWindow.onAttached();
		}
	}
	
	@Override
	public void setAdapter(SpinnerAdapter adapter) {
		super.setAdapter(adapter);
		mSwipeAdapter = (SwipeIndicatorAdapter) adapter;
		
		setOnItemSelectedListener(new Gallery.OnItemSelectedListener() {

			public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
				mSwipeAdapter.setSelectedIndicator(position);
			}

			public void onNothingSelected(AdapterView<?> parent) {
//				mSwipeAdapter.clearAllSelections();
			}
		});
	}


	public OnAttachedToWindow getOnAttachedToWindow() {
		return mOnAttachedToWindow;
	}


	public void setOnAttachedToWindow(OnAttachedToWindow mOnAttachedToWindow) {
		this.mOnAttachedToWindow = mOnAttachedToWindow;
	}
	

}
